﻿using System.Collections.Generic;
using System;
namespace TA.DotNetUtils
{
	public enum InclusionMode
	{
		OnlyIncluded = 0, AllExceptExcluded = 1
	}
	public static class _InclusionModeExtensions
	{
		public static bool IsIncluded<T>(this InclusionMode imThis, IEnumerable<T> list, T item)
		{
			return imThis.IsIncluded(list, t=>object.Equals(t, item));
		}
		public static bool IsIncluded<T>(this InclusionMode imThis, IEnumerable<T> list, Predicate<T> comparer)
		{
			if (list != null)
			{
				foreach (T t in list)
				{
					if (comparer(t))
						return imThis == InclusionMode.OnlyIncluded;
				}
			}
			return imThis == InclusionMode.AllExceptExcluded;
		}
		public static T[] GetActive<T>(this InclusionMode This, IEnumerable<T> list, IEnumerable<T> completeList)
		{
			List<T> res = new List<T>();
			switch (This)
			{
				case InclusionMode.OnlyIncluded:
					res.AddRange(list);
					break;
				case InclusionMode.AllExceptExcluded:
					foreach (T item in completeList)
					{
						bool found = false;
						foreach (T t in list)
						{
							if (object.Equals(item, t))
							{
								found = true; break;
							}
						}
						if (!found) res.Add(item);
					}
					break;
			}
			return res.ToArray();
		}
	}
}